package com.hc.tenant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hc.common.log.annotation.Log;
import com.hc.common.log.enums.BusinessType;
import com.hc.common.security.annotation.PreAuthorize;
import com.hc.tenant.domain.CookingType;
import com.hc.tenant.service.ICookingTypeService;
import com.hc.common.core.web.controller.BaseController;
import com.hc.common.core.web.domain.AjaxResult;
import com.hc.common.core.utils.poi.ExcelUtil;
import com.hc.common.core.web.page.TableDataInfo;

/**
 * 烹饪方式Controller
 * 
 * @author yongjianz
 * @date 2021-02-05
 */
@RestController
@RequestMapping("/cookingType")
public class CookingTypeController extends BaseController
{
    @Autowired
    private ICookingTypeService cookingTypeService;

    /**
     * 查询烹饪方式列表
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:list")
    @GetMapping("/list")
    public TableDataInfo list(CookingType cookingType)
    {
        startPage();
        List<CookingType> list = cookingTypeService.selectCookingTypeList(cookingType);
        return getDataTable(list);
    }

    /**
     * 导出烹饪方式列表
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:export")
    @Log(title = "烹饪方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CookingType cookingType) throws IOException
    {
        List<CookingType> list = cookingTypeService.selectCookingTypeList(cookingType);
        ExcelUtil<CookingType> util = new ExcelUtil<CookingType>(CookingType.class);
        util.exportExcel(response, list, "cookingType");
    }

    /**
     * 获取烹饪方式详细信息
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:query")
    @GetMapping(value = "/{cookingTypeId}")
    public AjaxResult getInfo(@PathVariable("cookingTypeId") Long cookingTypeId)
    {
        return AjaxResult.success(cookingTypeService.selectCookingTypeById(cookingTypeId));
    }

    /**
     * 新增烹饪方式
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:add")
    @Log(title = "烹饪方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CookingType cookingType)
    {
        return toAjax(cookingTypeService.insertCookingType(cookingType));
    }

    /**
     * 修改烹饪方式
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:edit")
    @Log(title = "烹饪方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CookingType cookingType)
    {
        return toAjax(cookingTypeService.updateCookingType(cookingType));
    }

    /**
     * 删除烹饪方式
     */
    @PreAuthorize(hasPermi = "tenant:cookingType:remove")
    @Log(title = "烹饪方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cookingTypeIds}")
    public AjaxResult remove(@PathVariable Long[] cookingTypeIds)
    {
        return toAjax(cookingTypeService.deleteCookingTypeByIds(cookingTypeIds));
    }
}
